package Error;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;

import IO.Log;

public class Error 
{
	public static HashMap<Integer, String> ed;
	public static Vector<String> log = new Vector<String>();
	public static String latest = null;
	
	public Error()
	{
		ed = new HashMap<Integer, String>();
		this.populateDictionary();
	}
	
	private void populateDictionary()
	{
		ed.put(10,"Cannot find Show file.");
		ed.put(11,"Cannot find Show file.");
		ed.put(12,"Cannot read Show file.");
		ed.put(20,"Cannot connect");
		ed.put(21, "Connection timed out");
		ed.put(22, "Connection timed out");
		ed.put(50, "Cannot start native look and feel");
	}
	
	private static String getValue(int errorNum)
	{
		Iterator<Entry<Integer, String>> i = ed.entrySet().iterator();
		String errorValue = "No Error Msg for #"+errorNum;
		while (i.hasNext()) 
		{
	        Map.Entry<Integer, String> data = (Map.Entry<Integer, String>) i.next();
	        if(data.getKey() == errorNum)
	        {
	        	errorValue = data.getValue();
	        }
	    }
		log.add(errorValue);
		return errorValue;
	}
	
	public static String getLatestError()
	{
		return log.lastElement();
	}
	
	public static void report(int errorNum)
	{
		Log.printErrorln(Error.getValue(errorNum));
	}

	public static void report(int errorNum, String string) 
	{
		Log.printErrorln(Error.getValue(errorNum)+": "+string);
	}
}
